/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ModuloRemotoUI.java
 *
 * Created on 25/Nov/2009, 12:25:18
 */
package remote;

import commonSources.Cartao;
import commonSources.Cliente;
import commonSources.Conta;
import commonSources.Funcionario;
import commonSources.Painel;
import java.awt.event.KeyEvent;
import java.util.Hashtable;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;

/**
 *
 * @author Filipe
 */
public class ModuloRemotoUI extends javax.swing.JFrame {

    private ModuloRemoto mr;
    private Hashtable<String, Cliente> clientes;
    private Hashtable<String, Funcionario> funcs;
    private Object[][] data;
    private int type;
    private int selectedRowCli;
    private int selectedRowFunc;
    private DefaultListModel modelContas;
    private Hashtable<String, Conta> contasDoHomem;

    /** Creates new form ModuloRemotoUI */
    public ModuloRemotoUI(ModuloRemoto mr) {
        modelContas = new DefaultListModel();
        this.mr = mr;
        clientes = mr.getClientes();
        funcs = mr.getFuncs();
        initComponents();
        fillTableClients();
        fillTableFuncs();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        panelFuncs = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tabelaFuncs = new javax.swing.JTable();
        butGuardarAlt1 = new javax.swing.JButton();
        butNovoCli1 = new javax.swing.JButton();
        butEditarCli1 = new javax.swing.JButton();
        txFNome1 = new javax.swing.JTextField();
        txFId1 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        butDelCli1 = new javax.swing.JButton();
        panelPub = new javax.swing.JPanel();
        panelResumos = new javax.swing.JPanel();
        panelClientes = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabelaClientes = new javax.swing.JTable();
        butGuardarAlt = new javax.swing.JButton();
        butNovoCli = new javax.swing.JButton();
        butEditarCli = new javax.swing.JButton();
        txFNome = new javax.swing.JTextField();
        txFId = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        butDelCli = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        listContas = new javax.swing.JList();
        Contas = new javax.swing.JLabel();
        butNovaConta = new javax.swing.JButton();
        txFSaldo = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txFPainelTxt = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txFPublImagePath = new javax.swing.JTextField();
        labelX = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(800, 600));

        jTabbedPane1.setMinimumSize(new java.awt.Dimension(800, 600));
        jTabbedPane1.setPreferredSize(new java.awt.Dimension(800, 600));

        tabelaFuncs.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "ID", "Nome"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        tabelaFuncs.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabelaFuncsMouseClicked(evt);
            }
        });
        tabelaFuncs.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tabelaFuncsKeyPressed(evt);
            }
        });
        jScrollPane3.setViewportView(tabelaFuncs);

        butGuardarAlt1.setText("Guardar Alterações");
        butGuardarAlt1.setEnabled(false);
        butGuardarAlt1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butGuardarAlt1ActionPerformed(evt);
            }
        });

        butNovoCli1.setLabel("Novo");
        butNovoCli1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butNovoCli1ActionPerformed(evt);
            }
        });

        butEditarCli1.setText("Editar");
        butEditarCli1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butEditarCli1ActionPerformed(evt);
            }
        });

        jLabel4.setText("ID");

        jLabel5.setText("Nome");

        butDelCli1.setText("Eliminar");
        butDelCli1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butDelCli1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelFuncsLayout = new javax.swing.GroupLayout(panelFuncs);
        panelFuncs.setLayout(panelFuncsLayout);
        panelFuncsLayout.setHorizontalGroup(
            panelFuncsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelFuncsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelFuncsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelFuncsLayout.createSequentialGroup()
                        .addComponent(butNovoCli1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(butEditarCli1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(butDelCli1))
                    .addComponent(txFId1, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel4)
                    .addComponent(txFNome1, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(butGuardarAlt1))
                .addContainerGap(122, Short.MAX_VALUE))
        );
        panelFuncsLayout.setVerticalGroup(
            panelFuncsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelFuncsLayout.createSequentialGroup()
                .addContainerGap(134, Short.MAX_VALUE)
                .addGroup(panelFuncsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelFuncsLayout.createSequentialGroup()
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(panelFuncsLayout.createSequentialGroup()
                        .addGroup(panelFuncsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(butNovoCli1)
                            .addComponent(butEditarCli1)
                            .addComponent(butDelCli1))
                        .addGap(19, 19, 19)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txFId1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(15, 15, 15)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txFNome1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32)
                        .addComponent(butGuardarAlt1)
                        .addContainerGap())))
        );

        butNovoCli1.getAccessibleContext().setAccessibleName("Novo Funcionário");

        jTabbedPane1.addTab("Gestão de Funcionários", panelFuncs);

        javax.swing.GroupLayout panelPubLayout = new javax.swing.GroupLayout(panelPub);
        panelPub.setLayout(panelPubLayout);
        panelPubLayout.setHorizontalGroup(
            panelPubLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 795, Short.MAX_VALUE)
        );
        panelPubLayout.setVerticalGroup(
            panelPubLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 572, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Gestão de Paineis", panelPub);

        javax.swing.GroupLayout panelResumosLayout = new javax.swing.GroupLayout(panelResumos);
        panelResumos.setLayout(panelResumosLayout);
        panelResumosLayout.setHorizontalGroup(
            panelResumosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 795, Short.MAX_VALUE)
        );
        panelResumosLayout.setVerticalGroup(
            panelResumosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 572, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Relatórios", panelResumos);

        tabelaClientes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "ID", "Nome", "Número de Contas"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Integer.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        tabelaClientes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabelaClientesMouseClicked(evt);
            }
        });
        tabelaClientes.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tabelaClientesKeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(tabelaClientes);

        butGuardarAlt.setText("Guardar Alterações");
        butGuardarAlt.setEnabled(false);
        butGuardarAlt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butGuardarAltActionPerformed(evt);
            }
        });

        butNovoCli.setText("Novo Cliente");
        butNovoCli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butNovoCliActionPerformed(evt);
            }
        });

        butEditarCli.setText("Editar Cliente");
        butEditarCli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butEditarCliActionPerformed(evt);
            }
        });

        jLabel1.setText("ID");

        jLabel2.setText("Nome");

        butDelCli.setText("Eliminar Cliente");
        butDelCli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butDelCliActionPerformed(evt);
            }
        });

        listContas.setModel(modelContas);
        listContas.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listContasValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(listContas);

        Contas.setText("Contas");

        butNovaConta.setText("Nova Conta");
        butNovaConta.setEnabled(false);
        butNovaConta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butNovaContaActionPerformed(evt);
            }
        });

        jLabel3.setText("€");

        jLabel6.setText("Texto da Publicidade");

        labelX.setText("Nome do ficheiro da publicidade");

        javax.swing.GroupLayout panelClientesLayout = new javax.swing.GroupLayout(panelClientes);
        panelClientes.setLayout(panelClientesLayout);
        panelClientesLayout.setHorizontalGroup(
            panelClientesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelClientesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelClientesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelClientesLayout.createSequentialGroup()
                        .addComponent(butNovoCli)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(butEditarCli)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(butDelCli))
                    .addComponent(txFId, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1)
                    .addComponent(butGuardarAlt)
                    .addComponent(butNovaConta)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelClientesLayout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txFSaldo, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3))
                    .addComponent(Contas)
                    .addComponent(txFPainelTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
                    .addComponent(jLabel6)
                    .addComponent(labelX)
                    .addGroup(panelClientesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(txFPublImagePath, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(txFNome, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)))
                .addContainerGap())
        );
        panelClientesLayout.setVerticalGroup(
            panelClientesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelClientesLayout.createSequentialGroup()
                .addContainerGap(132, Short.MAX_VALUE)
                .addGroup(panelClientesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(panelClientesLayout.createSequentialGroup()
                        .addGroup(panelClientesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(butNovoCli)
                            .addComponent(butEditarCli)
                            .addComponent(butDelCli))
                        .addGap(19, 19, 19)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txFId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(15, 15, 15)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txFNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(labelX)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txFPublImagePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txFPainelTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelClientesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelClientesLayout.createSequentialGroup()
                                .addComponent(Contas)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelClientesLayout.createSequentialGroup()
                                .addGroup(panelClientesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(txFSaldo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel3))
                                .addGap(30, 30, 30)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(butNovaConta)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(butGuardarAlt)))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Gestão de Clientes", panelClientes);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 800, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 600, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void butNovoCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butNovoCliActionPerformed
        type = 0;
        txFId.setText("");
        txFNome.setText("");
        txFPainelTxt.setText("");
        txFPublImagePath.setText("");
        modelContas.clear();
        butNovaConta.setEnabled(true);
        butGuardarAlt.setEnabled(true);
        try {
            contasDoHomem.clear();
        } catch (Exception e) {
            System.out.println("empty contas do homem");
        }
    }//GEN-LAST:event_butNovoCliActionPerformed

    private void butGuardarAltActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butGuardarAltActionPerformed
        String nome = txFNome.getText();
        String id = txFId.getText();
        String pubTxt = txFPainelTxt.getText();
        String pubImg = txFPublImagePath.getText();
        if (nome.length() != 0 && id.length() != 0 && pubImg.length() != 0 && pubTxt.length() != 0) {
            Painel p = new Painel("P" + id, pubTxt, pubImg);
            Cliente c = new Cliente(nome, id);
            c.setPainel(p);
            c.setContas(contasDoHomem);
            mr.adicionaCliente(c);
            clientes.put(id, c);
            JOptionPane.showMessageDialog(null, "Alteração efectuada com sucesso");
            butGuardarAlt.setEnabled(false);
            butNovaConta.setEnabled(false);
            fillTableClients();
        } else {
            JOptionPane.showMessageDialog(null, "É necessário preencher toods os campos");
        }
    }//GEN-LAST:event_butGuardarAltActionPerformed

    private void butEditarCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butEditarCliActionPerformed
        butGuardarAlt.setEnabled(true);
    }//GEN-LAST:event_butEditarCliActionPerformed

    private void tabelaClientesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelaClientesMouseClicked
        System.out.println("CLICK");
        selectedRowCli = tabelaClientes.getSelectedRow();
        selectionChangedCli();
    }//GEN-LAST:event_tabelaClientesMouseClicked

    private void tabelaClientesKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tabelaClientesKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_DOWN || evt.getKeyCode() == KeyEvent.VK_UP) {
            System.out.println("KEY");
            selectedRowCli = tabelaClientes.getSelectedRow();
            selectionChangedCli();
        }
    }//GEN-LAST:event_tabelaClientesKeyPressed

    private void butDelCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butDelCliActionPerformed
        int response;
        response = JOptionPane.showConfirmDialog(null, "Tem a certeza que quer eliminar este Cliente?");
        if (response == 0) {
            mr.eliminaCliente(tabelaClientes.getValueAt(selectedRowCli, 0) + "");
            clientes.remove(tabelaClientes.getValueAt(selectedRowCli, 0) + "");
            fillTableClients();
        }

    }//GEN-LAST:event_butDelCliActionPerformed

    private void butNovaContaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butNovaContaActionPerformed
        if (contasDoHomem == null) {
            contasDoHomem = new Hashtable<String, Conta>();
        }
        String id = (modelContas.size() + 1) + txFId.getText();
        contasDoHomem.put(id, new Conta(id));
        modelContas.addElement(contasDoHomem.get(id).getNumConta());

    }//GEN-LAST:event_butNovaContaActionPerformed

    @SuppressWarnings("empty-statement")
    private void listContasValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listContasValueChanged

        if (listContas.getSelectedValue() != null) {
            txFSaldo.setText(contasDoHomem.get((String) listContas.getSelectedValue()).getSaldo() + "");
        }
    }//GEN-LAST:event_listContasValueChanged

    private void tabelaFuncsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelaFuncsMouseClicked
        System.out.println("CLICK");
        selectedRowCli = tabelaFuncs.getSelectedRow();
        selectionChangedFunc();
    }//GEN-LAST:event_tabelaFuncsMouseClicked

    private void tabelaFuncsKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tabelaFuncsKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_DOWN || evt.getKeyCode() == KeyEvent.VK_UP) {
            System.out.println("KEY");
            selectedRowFunc = tabelaFuncs.getSelectedRow();
            selectionChangedFunc();
        }
    }//GEN-LAST:event_tabelaFuncsKeyPressed

    private void butGuardarAlt1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butGuardarAlt1ActionPerformed
        String nome = txFNome1.getText();
        String id = txFId1.getText();
        if (nome.length() != 0 && id.length() != 0) {
            Funcionario f = new Funcionario(nome, id);
            f.setCartao(new Cartao(9 + id, "0000", ""));
            mr.adicionaFuncionario(f);
            funcs.put(id, f);
            JOptionPane.showMessageDialog(null, "Alteração efectuada com sucesso");
            butGuardarAlt1.setEnabled(false);
            fillTableFuncs();
        } else {
            JOptionPane.showMessageDialog(null, "É necessário preencher todos os campos");
        }
    }//GEN-LAST:event_butGuardarAlt1ActionPerformed

    private void butNovoCli1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butNovoCli1ActionPerformed
        txFId1.setText("");
        txFNome1.setText("");
        txFPainelTxt.setText("");
        txFPublImagePath.setText("");
        butGuardarAlt1.setEnabled(true);
    }//GEN-LAST:event_butNovoCli1ActionPerformed

    private void butEditarCli1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butEditarCli1ActionPerformed
        butGuardarAlt1.setEnabled(true);
    }//GEN-LAST:event_butEditarCli1ActionPerformed

    private void butDelCli1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_butDelCli1ActionPerformed
        int response;
        response = JOptionPane.showConfirmDialog(null, "Tem a certeza que quer eliminar este Funcionário?");
        if (response == 0) {
            mr.eliminaFunc(tabelaFuncs.getValueAt(selectedRowCli, 0) + "");
            funcs.remove(tabelaFuncs.getValueAt(selectedRowCli, 0) + "");
            fillTableFuncs();
        }
    }//GEN-LAST:event_butDelCli1ActionPerformed

    private void fillTableClients() {
        System.out.println("clientes size: " + clientes.size());
        data = new Object[clientes.size()][3];
        int i = 0;
        for (Cliente cliente : clientes.values()) {
            data[i][0] = cliente.getId();
            data[i][1] = cliente.getNome();
            data[i][2] = cliente.numContas();
            i++;
        }
        tabelaClientes.setModel(new javax.swing.table.DefaultTableModel(
                data,
                new String[]{
                    "ID", "Nome", "Número de Contas"
                }) {

            Class[] types = new Class[]{
                java.lang.String.class, java.lang.String.class, java.lang.Integer.class
            };

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
            }

            @Override
            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }
        });

    }

    private void fillTableFuncs() {
        System.out.println("clientes size: " + funcs.size());
        data = new Object[funcs.size()][2];
        int i = 0;
        for (Funcionario func : funcs.values()) {
            data[i][0] = func.getIdFuncionario();
            data[i][1] = func.getNome();
            i++;
        }
        tabelaFuncs.setModel(new javax.swing.table.DefaultTableModel(
                data,
                new String[]{
                    "ID", "Nome"
                }) {

            Class[] types = new Class[]{
                java.lang.String.class, java.lang.String.class, java.lang.Integer.class
            };

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
            }

            @Override
            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }
        });

    }
//    /**
//     * @param args the command line arguments
//     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
//                new ModuloRemotoUI().setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel Contas;
    private javax.swing.JButton butDelCli;
    private javax.swing.JButton butDelCli1;
    private javax.swing.JButton butEditarCli;
    private javax.swing.JButton butEditarCli1;
    private javax.swing.JButton butGuardarAlt;
    private javax.swing.JButton butGuardarAlt1;
    private javax.swing.JButton butNovaConta;
    private javax.swing.JButton butNovoCli;
    private javax.swing.JButton butNovoCli1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JLabel labelX;
    private javax.swing.JList listContas;
    private javax.swing.JPanel panelClientes;
    private javax.swing.JPanel panelFuncs;
    private javax.swing.JPanel panelPub;
    private javax.swing.JPanel panelResumos;
    private javax.swing.JTable tabelaClientes;
    private javax.swing.JTable tabelaFuncs;
    private javax.swing.JTextField txFId;
    private javax.swing.JTextField txFId1;
    private javax.swing.JTextField txFNome;
    private javax.swing.JTextField txFNome1;
    private javax.swing.JTextField txFPainelTxt;
    private javax.swing.JTextField txFPublImagePath;
    private javax.swing.JTextField txFSaldo;
    // End of variables declaration//GEN-END:variables

    private void selectionChangedCli() {
        txFId.setText("" + tabelaClientes.getValueAt(selectedRowCli, 0));
        txFNome.setText("" + tabelaClientes.getValueAt(selectedRowCli, 1));
        txFSaldo.setText("");
        txFPainelTxt.setText(clientes.get(txFId.getText()).getPainel().getTexto());
        txFPublImagePath.setText(clientes.get(txFId.getText()).getPainel().getPathToImage());
        try {
            modelContas.clear();
            contasDoHomem = mr.getCliente("" + tabelaClientes.getValueAt(selectedRowCli, 0)).getContas();
            for (Conta conta : contasDoHomem.values()) {
                modelContas.addElement(conta.getNumConta());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void selectionChangedFunc() {
        txFId1.setText("" + tabelaFuncs.getValueAt(selectedRowFunc, 0));
        txFNome1.setText("" + tabelaFuncs.getValueAt(selectedRowFunc, 1));
    }
}
